/*
 * Copyright (c) 2017-2019 Vered Information Technology Corp.,Ltd. All rights reserved. 蔷薇信息技术有限公司版权所有.
 */
package com.chao.exception;

import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * 业务异常类，所有服务自定义业务异常需继承此类
 */
public class BusinessException extends RuntimeException implements Serializable {

    private static final long serialVersionUID = 3878528837115410642L;
    private String code;
    private String message;

    public BusinessException(){}

    public BusinessException(int code, String message) {
        super(message);
        this.message = message;
        this.code = String.valueOf(code);
    }

    public BusinessException( String message) {
        super(message);
        this.message = message;
    }


    
    public String getCode() {
        return this.code;
    }



    @Override
    public String getMessage(){
        return this.message;
    }

    protected void checkErrorCode(String errorCode){
        if(StringUtils.isNotEmpty(errorCode) && errorCode.length() != 3){
            throw new BusinessException(1,"请按照规范编写异常码（三位数字）");
        }
        try {
            Integer.valueOf(errorCode);
        } catch (Exception e) {
            throw new BusinessException(1,"请按照规范编写异常码（三位数字）");
        }
    }


}
